package com.nursing.controller.Elder;

import com.github.pagehelper.PageInfo;
import com.nursing.bean.Elder;
import com.nursing.model.Result;
import com.nursing.service.ElderService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/elder")
public class ElderUserController {
    private final ElderService elderService;

    public ElderUserController(ElderService elderService) {
        this.elderService = elderService;
    }

    @GetMapping("/list")
    public Result<PageInfo<Elder>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10")int size) {
        return Result.success(elderService.list(page, size));
    }

    @PostMapping("/add")
    public Result<Elder> add(@RequestBody Elder elder) {
        elderService.addElder(elder);
        return Result.success("添加成功");
    }

    @PostMapping("/update")
    public Result<Elder> update(@RequestBody Elder elder) {
        elderService.updateElder(elder);
        return Result.success("修改成功");
    }

    @DeleteMapping("/delete")
    public Result<Elder> delete(@RequestParam Integer id) {
        elderService.deleteElder(id);
        return Result.success("删除成功");
    }

    @GetMapping("/getElderById")
    public Result<Elder> getElderById(@RequestParam Integer id) {
        return Result.success(elderService.getElderById(id));
    }


}
